package com.example.framework.fragment;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.framework.R;
import com.example.framework.activity.OKHttpActivity;
import com.example.framework.adapter.CommonFrameFragmentAdapter;
import com.example.framework.base.BaseFragment;
import com.example.framework.glide.activity.GlideActivity;
import com.example.framework.json.activity.GsonActivity;
import com.example.framework.json.activity.NativeJsonPraseActivity;
import com.example.framework.picasso.activity.PicassoActivity;
import com.example.framework.volley.VolleyActivity;

/**
 * 作者：尚硅谷-杨光福 on 2016/7/21 19:27
 * 微信：yangguangfu520
 * QQ号：541433511
 * 作用：常用框架Fragment
 */
public class CommonFrameFragment extends BaseFragment
{
      
      private ListView mListView;
      
      private String[] datas;
      
      private CommonFrameFragmentAdapter adapter;
      
      
      private static final String TAG = CommonFrameFragment.class.getSimpleName();//"CommonFrameFragment"
      
      @Override
      protected void initData()
      {
            super.initData();
            Log.e(TAG, "常用框架Fragment数据被初始化了...");
            //准备数据
            datas = new String[]{"OKHttp", "原生json解析", "Gson", "volley", "picasso **", "glide","jcvideoplayer", "pulltorefresh", "Expandablelistview", "UniversalVideoView", "....."};
            //设置适配器
            adapter = new CommonFrameFragmentAdapter(mContext, datas);
            mListView.setAdapter(adapter);
      }
      
      @Override
      protected View initView()
      {
            Log.e(TAG, "常用框架Fragment页面被初始化了...");
            View view = View.inflate(mContext, R.layout.fragment_common_frame, null);
            mListView = (ListView) view.findViewById(R.id.listview);
            mListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
                  @Override
                  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                  {
                        String data = datas[position];
                        
                        
                        if (data.toLowerCase().equals("okhttp"))
                        {
                              Intent intent = new Intent(mContext, OKHttpActivity.class);
                              mContext.startActivity(intent);
                        }
                        else if (data.toLowerCase().equals("原生json解析"))
                        {
                              Intent intent = new Intent(mContext, NativeJsonPraseActivity.class);
                              startActivity(intent);
                        }
                        else if (data.toLowerCase().equals("gson"))
                        {
                              Intent intent = new Intent(mContext, GsonActivity.class);
                              startActivity(intent);
                        }
                        else if (data.toLowerCase().equals("volley"))
                        {
                              Intent intent = new Intent(mContext, VolleyActivity.class);
                              startActivity(intent);
                        }
                        else if (data.toLowerCase().equals("picasso **"))
                        {
                              Intent intent = new Intent(mContext, PicassoActivity.class);
                              startActivity(intent);
                        }
                        else if (data.toLowerCase().equals("glide要高版本,以后看"))
                        {
                              //低版本使用了 v4 包. 所以放弃
                              Intent intent = new Intent(mContext, GlideActivity.class);
                              startActivity(intent);
                        }
                  }
            });
            return view;
      }
      
      
}
